package com.xinqi.modules.sys.stats.manager.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.mybatis.data.service.impl.BaseServiceImpl;
import com.xinqi.modules.sys.stats.domain.ClassTeachingDayStEntity;
import com.xinqi.modules.sys.stats.dto.req.ClassTeachingDayStQueryDTO;
import com.xinqi.modules.sys.stats.dto.req.ClassTeachingOverviewQueryDTO;
import com.xinqi.modules.sys.stats.dto.rsp.ClassOverviewResultDTO;
import com.xinqi.modules.sys.stats.dto.rsp.ClassTeachingCountResultDTO;
import com.xinqi.modules.sys.stats.dto.rsp.ClassTeachingDayStResultDTO;
import com.xinqi.modules.sys.stats.manager.ClassTeachingDayStManager;
import com.xinqi.modules.sys.stats.mapper.ClassTeachingDayStMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

/**
 * 班级教学数据统计管理层实现
 *
 * @author: wenjie
 * @date: 2023/08/24
 */
@Service
@RequiredArgsConstructor
public class ClassTeachingDayStManagerImpl extends BaseServiceImpl<ClassTeachingDayStMapper, ClassTeachingDayStEntity> implements ClassTeachingDayStManager {

    /**
     * 自定义分页查询
     */
    @Override
    public Page<ClassTeachingDayStResultDTO> findPage(Page<Object> page, String schoolName, LocalDateTime startTime, LocalDateTime endTime) {
        return this.baseMapper.findPage(page, schoolName, startTime, endTime);
    }

    /**
     * 自定义列表查询
     */
    @Override
    public List<ClassTeachingDayStResultDTO> findList(ClassTeachingDayStQueryDTO query) {
        return this.baseMapper.findList(query);
    }

    /**
     * 根据id查询 班级教学数据统计数据
     */
    @Override
    public ClassTeachingDayStEntity findById(Long id) {
        CommonErrors.BAD_REQUEST.check(Objects.nonNull(id), "ID不能为空");
        return getById(id);
    }

    /**
     * 根据id删除 班级教学数据统计数据
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteById(Long id) {
        CommonErrors.BAD_REQUEST.check(Objects.nonNull(id), "ID不能为空");
        return this.removeById(id);
    }

    @Override
    public List<ClassTeachingCountResultDTO> findCourseContentCountByTypeAndCourseClassIdListAndDateRange(Integer type, List<Long> courseClassIdList, LocalDateTime startTime, LocalDateTime endTime) {
        return this.baseMapper.findCourseContentCountByTypeAndCourseClassIdListAndDateRange(type, courseClassIdList, startTime, endTime);
    }


    @Override
    public List<ClassTeachingCountResultDTO> findCurrentDateReleaseHomeworkByTypeAndCourseClassIdListAndDateRange(Integer type, List<Long> courseClassIdList, LocalDateTime startTime, LocalDateTime endTime) {
        return this.baseMapper.findCurrentDateReleaseHomeworkByTypeAndCourseClassIdListAndDateRange(type, courseClassIdList, startTime, endTime);
    }

    @Override
    public ClassOverviewResultDTO overview(ClassTeachingOverviewQueryDTO query) {
        return this.baseMapper.overview(query);
    }

    @Override
    public IPage<ClassTeachingDayStEntity> findPageBySchoolNameList(Page<ClassTeachingDayStEntity> page, List<String> schoolNameList) {
        return this.baseMapper.findPageBySchoolNameList(page, schoolNameList);
    }

    @Override
    public List<ClassTeachingCountResultDTO> findContentSortListAndDateRange(String schoolName, LocalDateTime startTime, LocalDateTime endTime) {
        return this.baseMapper.findContentSortListAndDateRange(schoolName, startTime, endTime);
    }

}
